package leetcode.day_2020_2021_2_1_2021_2_7;

/**
 * 26. 删除排序数组中的重复项
 * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
 */
public class LeetCode0026 {
    public static void main(String[] args) {
        System.out.println(removeDuplicates(new int[]{1, 2, 2}));
    }

    public static int removeDuplicates(int[] nums) {
        if (nums.length == 1) return 1;
        int slow = 0, count = 1;
        for (int i=1; i<nums.length; i++) {
            if (nums[i] != nums[slow]) {
                nums[slow+1] = nums[i];
                slow = slow + 1;
                count = count + 1;
            }
        }
        return count;
    }
}
